package com.letoken.platform.repo.app.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.app.po.VideoComment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface VideoCommentsMapper extends BaseMapper<VideoComment> {


    @Update("update video_comments set replies_count = replies_count + #{count} where id = #{id}")
    void incrementRepliesCountById(@Param("id") Integer id, @Param("count") Integer count);

    @Update("update video_comments set likes_user_ids = if(likes_user_ids is null, #{likeUserId} , CONCAT(likes_user_ids, ',', #{likeUserId}))   where id = #{id}")
    void like(@Param("id") Integer id, @Param("likeUserId") Integer likeUserId);

    @Update("update video_comments set likes_user_ids = if(INSTR(likes_user_ids, #{likeUserId}) = 1 , replace(likes_user_ids, CONCAT(#{likeUserId},',') , '') ,#{likeUserId}) where id = #{id}")
    void unlike(@Param("id") Integer id, @Param("likeUserId") Integer likeUserId);

    @Select("select * from  video_comments where video_id = #{videoId}")
    Page<VideoComment> page(@Param("page") Page<VideoComment> page,@Param("videoId") Integer videoId);

}
